package hust.rpc.proxy;

import java.lang.reflect.InvocationTargetException;

public class AllProxy extends Proxy {

    private final ConsumerProxy consumerProxy = new ConsumerProxy();
    private final ProviderProxy providerProxy = new ProviderProxy();

    @Override
    protected <T> T getInternalProxy(Class<T> clazz) {
        if (clazz.isInterface()) {
            return consumerProxy.getProxy(clazz);
        }
        return providerProxy.getProxy(clazz);
    }

    @Override
    public <T> T getProxy(Class<T> clazz) {
        return getInternalProxy(clazz);
    }

    @Override
    public Object invoke(String signature, Object[] args) throws InvocationTargetException, IllegalAccessException {
        return providerProxy.invoke(signature, args);
    }
}
